package com.yf.zzmusic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yf.zzmusic.common.PageInfo;
import com.yf.zzmusic.common.Result;
import com.yf.zzmusic.pojo.dto.album.AlbumDetailsDTO;
import com.yf.zzmusic.pojo.dto.albumRecord.AlbumRecordDeleteDTO;
import com.yf.zzmusic.pojo.vo.music.MusicTableVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import com.yf.zzmusic.service.IAlbumRecordService;
import com.yf.zzmusic.pojo.entity.AlbumRecord;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 专辑记录表 前端控制器
 * </p>
 *
 * @author
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/albumrecord")
public class AlbumRecordController {
  @Resource
  private IAlbumRecordService albumRecordService;

  @PostMapping("/insert")
  public Result save(@RequestBody AlbumRecord albumRecord) {
    boolean result = albumRecordService.save(albumRecord);
    if (result) {
      return Result.success("新增成功", null);
    } else {
      return Result.error("新增失败");
    }
  }

  @DeleteMapping("/{id}")
  public Result delete(@PathVariable Integer id) {
    boolean result = albumRecordService.removeById(id);
    if (result) {
      return Result.success("删除成功", null);
    } else {
      return Result.error("删除失败");
    }
  }

  @GetMapping("/{id}")
  public Result findOne(@PathVariable Integer id) {
    AlbumRecord albumRecord = albumRecordService.getById(id);
    if (albumRecord != null) {
      return Result.success("查询成功", albumRecord);
    } else {
      return Result.error("查询失败");
    }
  }

  @GetMapping("/page")
  public Result findPage(@Validated AlbumDetailsDTO albumDetailsDTO) {
    PageInfo<MusicTableVO> musicTableVOPageInfo = albumRecordService.albumMusicList(albumDetailsDTO);
    if (musicTableVOPageInfo.getData().size() > 0) {
      return Result.success("查询成功", musicTableVOPageInfo);
    } else {
      return Result.error("查询失败");
    }
  }

  @DeleteMapping("/delete")
  public Result deleteAlbumInMusic(@Validated AlbumRecordDeleteDTO albumRecordDeleteDTO) {
    boolean result = albumRecordService.deleteAlbumRecord(albumRecordDeleteDTO);
    if (result) {
      return Result.success("删除成功", null);
    } else {
      return Result.error("删除失败");
    }
  }
}

